/*
 * @Description: 应用
 * @Version: 1.0
 * @Autor: jiajun wu
 * @Date: 2021-11-24 09:43:54
 * @LastEditors: jiajun wu
 * @LastEditTime: 2021-11-25 16:12:34
 */

import { Module } from "vuex";
import { RootStateInterface } from "./rootStateInterface";
import { ACCESS_TOKEN } from "../mutation-types";
import { Cookie, LocalStorage, SessionStorage } from "@/utils/storage";


export interface AppState {
  /** token */
  appToken: string | null
}

const app: Module<AppState, RootStateInterface> = {
  namespaced: true,
  state: {
    appToken: null
  },
  getters: {
    appToken: state => state.appToken
  },
  mutations: {
    SET_TOKEN(state: AppState, token: string) {
      state.appToken = token
    },
  },
  actions: {
    setToken({ commit }, token) {
      LocalStorage.set(ACCESS_TOKEN, token)
      SessionStorage.set(ACCESS_TOKEN, token)
      Cookie.set(ACCESS_TOKEN, token)
      commit("SET_TOKEN", token);
    }
  }
}

export default app